{% extends ../base.html %}

{% block head %}
<style type="text/css">
img {
    max-width: 100%;
}
</style>
{% end %}

{% block body %}

    {% include "header.html" %}

{% if op == "view" %}
    <h2 id="name">{{file["name"]}}</h2>

    <p>
        <span>{{file.smtime}}</span>
        <a href="/file/post/edit?id={{file.id}}">编辑</a>
    </p>
    <hr/>
    <div style="font-family:Consolas,monospace;word-wrap: break-word;">{% raw file["content"] %}</div>
    <br/>
    <a href="javascript:deleteConfirm()">删除</a>
    <script type="text/javascript">
    function deleteConfirm () {
        var name = $("#name").text();
        var conf = confirm("确认删除 " + name + " 吗?");
        if (conf) {
            window.location.href = "/file/post/del?id={{file.id}}";
        }
    }
    </script>
{% else %}
    <form method="POST" enctype="multipart/form-data">
        <p>
            <input name="name" type="text" value="{{file.name}}">
            {% if file.groups == "*" %}
                <input name="public" type="checkbox" checked>
            {% else %}
                <input name="public" type="checkbox">
            {% end %}
            所有人可见
            <a href="/file/post?id={{file.id}}" style="float:right">预览</a>
        </p>

    
        <div>
            <input type="file" name="file"/>
            <button>上传图片</button>
        </div>

        <textarea name="content" style="width:100%;margin-top:10px;font-family:monospace;" rows={{rows}}>{{file.content}}</textarea>
        <button>保存</button>
    </form>
{% end %}

{% end %}